-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
55 lines (43 loc) · 965 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void BubbleSort(char **nome, int pTam);
int main()
{
int k, n;
scanf("%d %d", &k, &n);
char **nome = NULL;
nome = malloc(k * sizeof(char *));
for (int i = 0; i < k; i++)
{
nome[i] = malloc(21 * sizeof(char));
//scanf("%s", nome[i]);
}
for (int i = 0; i < k; i++)
scanf("%s", nome[i]);
BubbleSort(nome, k);
printf("%s\n", nome[n - 1]);
for (int i = 0; i < k; i++)
free(nome[i]);
free(nome);
return 0;
}
void BubbleSort(char **nome, int pTam)
{
int trocou;
char aux[21];
do
{
trocou = 0;
for (int i = 0; i < pTam - 1; i++)
{
if (strcmp(nome[i], nome[i + 1]) > 0)
{
strcpy(aux, nome[i]);
strcpy(nome[i], nome[i + 1]);
strcpy(nome[i + 1], aux);
trocou = 1;
}
}
} while (trocou);
}